/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainScreen.java
 *
 * Created on 10/01/2010, 03:02:05
 */

package br.com.barrientosjunior.massfilerenamer.view;

import br.com.barrientosjunior.massfilerenamer.controller.MainScreenController;
import br.com.barrientosjunior.massfilerenamer.resources.Constants;
import java.io.File;
import javax.swing.JOptionPane;
import javax.swing.JProgressBar;

/**
 * System's main screen.
 * @author Junior
 */
public class MainScreen extends javax.swing.JFrame {

    private MainScreenController mainScreenController = null;

    /** Creates new form MainScreen */
    public MainScreen(MainScreenController mainScreenController) {
        this.mainScreenController = mainScreenController;
        initComponents();
    }

    public JProgressBar getRenameJProgressBar() {
        return renameJProgressBar;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        inputFolderInfoJLabel = new javax.swing.JLabel();
        inputFolderJTextField = new javax.swing.JTextField();
        chooseInputFolderJButton = new javax.swing.JButton();
        inputfolderInfoJLabel = new javax.swing.JLabel();
        outputFileNamePatternJTextField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        outputFolderJTextField = new javax.swing.JTextField();
        chooseOutputFolderJButton = new javax.swing.JButton();
        jLabel5 = new javax.swing.JLabel();
        renameFilesJButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        previewJTextArea = new javax.swing.JTextArea();
        renameJProgressBar = new javax.swing.JProgressBar();
        patternHelpJButton = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        filterJTextField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        previewJButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Renomeador de Arquivos em Massa");
        setName("frameMainScreen"); // NOI18N
        setResizable(false);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        inputFolderInfoJLabel.setText("Diretório dos arquivos a serem renomeados:");

        inputFolderJTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                inputFolderJTextFieldActionPerformed(evt);
            }
        });

        chooseInputFolderJButton.setText("Navegar...");
        chooseInputFolderJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chooseInputFolderJButtonActionPerformed(evt);
            }
        });

        inputfolderInfoJLabel.setText("Padrão de renomeação de arquivo:");

        outputFileNamePatternJTextField.setToolTipText(""); // NOI18N

        jLabel3.setText("Pasta de saída: (Mantém os arquivos originais intactos)");

        outputFolderJTextField.setToolTipText("");

        chooseOutputFolderJButton.setText("Navegar...");
        chooseOutputFolderJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chooseOutputFolderJButtonActionPerformed(evt);
            }
        });

        jLabel5.setText("Preview de resultado:");

        renameFilesJButton.setText("Renomear arquivos");
        renameFilesJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                renameFilesJButtonActionPerformed(evt);
            }
        });

        previewJTextArea.setBackground(javax.swing.UIManager.getDefaults().getColor("Panel.background"));
        previewJTextArea.setColumns(20);
        previewJTextArea.setEditable(false);
        previewJTextArea.setRows(2);
        previewJTextArea.setBorder(null);
        jScrollPane1.setViewportView(previewJTextArea);

        patternHelpJButton.setText("Ajuda?");
        patternHelpJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                patternHelpJButtonActionPerformed(evt);
            }
        });

        jLabel6.setText("Filtro de arquivos:");

        jLabel7.setText("(Exemplo \".jpg\". Deixar vazio irá alterar todos os arquivos da pasta)");

        previewJButton.setText("Visualização prévia");
        previewJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                previewJButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(inputFolderInfoJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(inputFolderJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(chooseInputFolderJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(inputfolderInfoJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(outputFileNamePatternJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(patternHelpJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(outputFolderJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(chooseOutputFolderJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 430, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(previewJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(renameFilesJButton, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(renameJProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 450, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(filterJTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 446, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addComponent(inputFolderInfoJLabel)
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(inputFolderJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(chooseInputFolderJButton))
                .addGap(7, 7, 7)
                .addComponent(inputfolderInfoJLabel)
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(outputFileNamePatternJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(patternHelpJButton))
                .addGap(7, 7, 7)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(6, 6, 6)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(outputFolderJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(chooseOutputFolderJButton))
                .addGap(7, 7, 7)
                .addComponent(jLabel6)
                .addGap(6, 6, 6)
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(filterJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(previewJButton)
                .addGap(7, 7, 7)
                .addComponent(jLabel5)
                .addGap(6, 6, 6)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(renameFilesJButton)
                .addGap(7, 7, 7)
                .addComponent(renameJProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void inputFolderJTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_inputFolderJTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_inputFolderJTextFieldActionPerformed

    private void chooseInputFolderJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseInputFolderJButtonActionPerformed
        this.inputFolderJTextField.setText(mainScreenController.chooseFileOrFolder());
    }//GEN-LAST:event_chooseInputFolderJButtonActionPerformed

    private void patternHelpJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_patternHelpJButtonActionPerformed
        JOptionPane.showMessageDialog(this,
                Constants.HELP);
    }//GEN-LAST:event_patternHelpJButtonActionPerformed

    private void chooseOutputFolderJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chooseOutputFolderJButtonActionPerformed
        this.outputFolderJTextField.setText(mainScreenController.chooseFileOrFolder());
    }//GEN-LAST:event_chooseOutputFolderJButtonActionPerformed

    private void renameFilesJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_renameFilesJButtonActionPerformed
        this.mainScreenController.renameFiles(this.inputFolderJTextField.getText(),
                this.outputFolderJTextField.getText(),
                this.outputFileNamePatternJTextField.getText(),
                this.filterJTextField.getText());
    }//GEN-LAST:event_renameFilesJButtonActionPerformed

    private void previewJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_previewJButtonActionPerformed

        previewJTextArea.setText(
                mainScreenController.previewOutputFileName(this.inputFolderJTextField.getText(),
                                                           this.outputFileNamePatternJTextField.getText(),
                                                           this.filterJTextField.getText()));
    }//GEN-LAST:event_previewJButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton chooseInputFolderJButton;
    private javax.swing.JButton chooseOutputFolderJButton;
    private javax.swing.JTextField filterJTextField;
    private javax.swing.JLabel inputFolderInfoJLabel;
    private javax.swing.JTextField inputFolderJTextField;
    private javax.swing.JLabel inputfolderInfoJLabel;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField outputFileNamePatternJTextField;
    private javax.swing.JTextField outputFolderJTextField;
    private javax.swing.JButton patternHelpJButton;
    private javax.swing.JButton previewJButton;
    private javax.swing.JTextArea previewJTextArea;
    private javax.swing.JButton renameFilesJButton;
    private javax.swing.JProgressBar renameJProgressBar;
    // End of variables declaration//GEN-END:variables

}
